package com.cloud.system.interfaces;

import com.cloud.system.api.bean.ByteFile;
import com.cloud.system.api.entity.Media;
import com.cloud.system.common.config.FeignConfiguration;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


@FeignClient(value = "MEDIA",  configuration = FeignConfiguration.class, fallbackFactory = FeignClientMediaFallbackFactory.class)
public interface FeignClientMedia {

    /** 每周通知自动上传 */
    @RequestMapping(value = "media/interface/autoupload", method = RequestMethod.POST)
    Media autoUpload(@RequestBody ByteFile file);

    /** 获取附件地址 */
    @RequestMapping(value = "media/interface/getAllMediaByIds", method = RequestMethod.GET)
    List<Media> getAllMediaByIds(@RequestBody List<String> ids);

}
@Component
class FeignClientMediaFallbackFactory implements FallbackFactory<FeignClientMedia> {
    private static final Logger LOGGER = LoggerFactory.getLogger(FeignClientMediaFallbackFactory.class);

    @Override
    public FeignClientMedia create(Throwable throwable) {
        return new FeignClientMedia() {

            @Override
            public Media autoUpload(ByteFile file) {
                return null;
            }

            @Override
            public List<Media> getAllMediaByIds(List<String> ids) {
                return null;
            }
        };
    }
}
